package com.aidong.dynamic.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.aidong.myprofile.biz.MyAidongTimeBiz;
import com.aidong.util.ReadPropertiesUtil;
import com.opensymphony.xwork2.ActionContext;

/**
 * 运动圈分享
 * @author user
 *
 */
@ParentPackage("struts")
@Namespace("/")
public class TrnDynamicSharingAction {
	
	private MyAidongTimeBiz aidongTimeBiz;
	
	@Autowired
	public void setAidongTimeBiz(MyAidongTimeBiz aidongTimeBiz) {
		this.aidongTimeBiz = aidongTimeBiz;
	}

	private int dynamicId;

	public void setDynamicId(int dynamicId) {
		this.dynamicId = dynamicId;
	}
	
	@Action(value="dynamicsharing",results={@Result(name="succ",type="redirect", location = "html/sharing_circle.jsp")})
	public String dynamicSharing(){
		if(dynamicId > 0){
			Map<String, Object> detailMap = aidongTimeBiz.getMyAidongTimeDetail(dynamicId);
			detailMap.put("headUrl", ReadPropertiesUtil.getIMGREAD(detailMap.get("headUrl")));
			detailMap.put("picUrl", ReadPropertiesUtil.getIMGREAD(detailMap.get("picUrl")));
			
			// 点赞列表
			List<Map<String, Object>> praisesMap = aidongTimeBiz.getTrnPraiseByOne(dynamicId);
			if(praisesMap.size() > 0){
				for (Map<String, Object> praises : praisesMap) {
					String praHeadUrl = praises.get("headUrl") + "";
					if(!"".equals(praHeadUrl) && praHeadUrl != null){
						praises.put("headUrl", ReadPropertiesUtil.getIMGREAD(praHeadUrl));
					}else{
						praises.put("headUrl", "");
					}
				}
			}
			
			// 评论列表
			List<Map<String, Object>> commentsMap = aidongTimeBiz.getTrnDynamicCommentByOne(dynamicId);
			if(commentsMap.size() > 0){
				for (Map<String, Object> comments : commentsMap) {
					String comHeadUrl = comments.get("headUrl") + "";
					if(!"".equals(comHeadUrl) && comHeadUrl != null){
						comments.put("headUrl", ReadPropertiesUtil.getIMGREAD(comHeadUrl));
					}else{
						comments.put("headUrl", "");
					}
				}
			}
			
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("detail", detailMap);
			map.put("praises", praisesMap);
			map.put("comments", commentsMap);
			ActionContext.getContext().getSession().put("rs",map);
			return "succ";
		}else{
			return null;
		}
	}
}
